package org.scct.chenhui.dao;

import org.scct.chenhui.model.BookPublishBean;
import org.scct.chenhui.utils.DBUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class BookPublishDao {


    public List<BookPublishBean> getAllPubliser()
    {
        String sql="select * from bm_book_publish";
        List<BookPublishBean> publishers = new ArrayList<>();
        Connection connection = DBUtils.getConnection();
        try {
            PreparedStatement pstmt = connection.prepareStatement(sql);
            ResultSet rs = pstmt.executeQuery();
            while (rs.next())
            {
                int id = rs.getInt("id");
                String name = rs.getString("name");
                BookPublishBean pub = new BookPublishBean(id, name);
                publishers.add(pub);
            }

        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return publishers;
    }

}
